#ifndef VIEW_AUTOUI_H
#define VIEW_AUTOUI_H

#include <QWidget>
#include <QPushButton>
#include <QDialog>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPainter>
#include <QProgressBar>
#include <QtMath>
#include <QThread>
#include "mgr_trace.h"

class SharedMemSend: public QObject {
    Q_OBJECT
public slots:
    void runSend() { sendDataToShm(); }
};

class SharedMemRecv: public QObject {
    Q_OBJECT
public slots:
    void runRecv() { receiveDataFromShm(); }
};

class QPoint3D {
    public:
        QPoint3D(int x = 0, int y = 0, int z = 0) 
            : m_x(x), m_y(y), m_z(z) {}
        
        int x() const { return m_x; }
        int y() const { return m_y; }
        int z() const { return m_z; }
        
    private:
        int m_x, m_y, m_z;
    };

class GyroDisplay : public QWidget {
    Q_OBJECT
public:
    explicit GyroDisplay(QWidget *parent = nullptr);
    void updateOrientation(float roll, float pitch, float yaw);

protected:
    void paintEvent(QPaintEvent *) override;

private:
    void draw3DAxis(QPainter &painter);
    void drawAttitudeIndicator(QPainter &painter);
    
    float m_roll = 0;  
    float m_pitch = 0;  
    float m_yaw = 0;    
};

class View_AutoUI : public QWidget {
    Q_OBJECT
public:
    explicit View_AutoUI(QWidget *parent = nullptr);
    ~View_AutoUI();
private slots:
    void showPidDialog();
    void showVersionDialog();
    void showVoltageDialog();

private:
    QWidget* createLeftPanel();  
    QWidget* createRightPanel(); 
    void createCenterPanel();       

    QPushButton *BackToMainBtn;
    GyroDisplay *gyroDisplay;
    
    QDialog *createInfoDialog(const QString &title, const QString &content);

    SharedMemSend sharedMemSend;
    SharedMemRecv sharedMemRecv;
    QThread sendThread;
    QThread recvThread;
signals:
    void AutoswitchToDesktop();
};

#endif // VIEW_AUTOUI_H
